package com.xunfang.controller;

import com.xunfang.bean.Order;
import com.xunfang.bean.Result;
import com.xunfang.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yellow Docter
 * @date 2023 -11-20
 * @desc
 */
@CrossOrigin   //解决跨域问题
@RestController
@RequestMapping("order")
public class OrderController {

    @Autowired
    private IOrderService orderService;

    @PostMapping
    public Result addOrder(@RequestBody Order order){
        boolean b = orderService.addOrders(order);
        return  Result.ok(b ? "操作成功":"操作失败");
    }

    @GetMapping
    public Result findOrders(){
        List<Order> orders = orderService.findOrders();
        return  Result.ok(orders);
    }

    @DeleteMapping("{id}")
    public Result deleteOrderById(@PathVariable int id){
        boolean b = orderService.deleteOrderById(id);
        return  Result.ok(b ? "操作成功":"操作失败");
    }
}
